<template>
  <div id="index">
    <div id="header">
      <div class="firstView">
        <img src="/static/images/user.png" alt="">
        <div>
          <span style="line-height: 2rem;text-align: center;font-size: 1.2rem;width: max-content;padding-left: 0.7rem">老茶馆--{{allData.table}}号桌</span>
          <span style="line-height: 1.5rem;text-align: center;font-size: 0.96rem;width: max-content;padding-left: 0.7rem;color: #6a6a6a">用餐时间：{{allData.time}}</span>
          <span style="line-height: 1.5rem;text-align: center;font-size: 0.96rem;width: max-content;padding-left: 0.7rem;color: #6a6a6a">用餐人数：2人</span>
        </div>
      </div>
    </div>
    <div id="section">
      <div class="orderItem">
        <span class="time">下单时间：{{allData.time}}</span>
        <div class="detailItem" v-for="(item,index) in orders" v-bind:key="index">
          <span class="name">{{item.m_name}}</span>
          <span class="number" style="margin-left: auto;margin-right: 2rem">X{{item.m_number}}</span>
        </div>
      </div>
    </div>
    <div id="footer">
      <span>总金额:</span>
      <span class="totalPrice">￥{{allData.totalPrice}}</span>
      <button @click="toOrder()">继续点餐</button>
      <button class="order" @click="pay()">去结算</button>
    </div>
    <div class="dialog" :style="{'display': dialog1Display}">
      <span class="success">下单成功</span>
      <span class="wait">世间美好的东西，都值得用心等待</span>
      <button @click="dialog1Confirm()">确认</button>
    </div>
    <div class="dialog" :style="{'display': dialog2Display}">
      <span class="success">温馨提示</span>
      <span class="wait">请到前台结账，谢谢合作</span>
      <span>欢迎您的下次光临</span>
      <button @click="dialog2Confirm()">确认</button>
    </div>
  </div>
</template>

<script>
  export default {
    name: "index",
    data(){
      return{
        allData:{},
        orders:[],
        dialog1Display: 'auto',
        dialog2Display: 'none'
      }
    },
    methods:{
      toOrder(){
        wx.navigateTo({
          url:'/pages/order/main'
        })
      },
      pay(){
        this.dialog2Display = 'auto';
      },
      dialog1Confirm(){
        this.dialog1Display = 'none';
      },
      dialog2Confirm(){
        this.dialog2Display = 'none';
      }
    },
    mounted(){
      Object.assign(this.$data, this.$options.data());
      if(this.$mp.query.status === '1'){
        this.dialog1Display = 'none';
      }
      if(this.$mp.query.status === '2'){
        this.dialog1Display = 'none';
        this.dialog2Display = 'auto';
      }
      if(this.$mp.query.id){
        let body = {
          O_id:this.$mp.query.id.toString()
        };
        console.log(body);
        this.$axios.get("getOrderItem",body).then(res=>{
          this.allData = res.data;
          this.allData.time = this.allData.time.toString().slice(0, -2);
          this.allData.table = this.allData.table.toString().slice(-1);
          this.allData.totalPrice = parseInt(this.allData.totalPrice);
          this.orders = this.allData.orderItems;
          console.log(this.orders)
        });
        console.log(this.$mp.query.id);
      }
    }
  }
</script>

<style scoped>
  #index{
    width: 100%;
    height: 100%;
  }
  #header{
    padding-top: 0.3rem;
    background: #E5A01C;
    width: 100%;
    height: 15.5%;
    display: flex;
    flex-direction: column;
  }
  .firstView{
    height: min-content;
    display: flex;
    flex-direction: row;
  }
  .firstView img{
    margin-left: 0.25rem;
    width: 1.7rem;
    height: 1.3rem;
  }
  .firstView div{
    display: flex;
    flex-direction: column;
  }
  #section{
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 75%;
    margin-top: 0.3rem;
    background: #f2e5ca;
    padding-bottom: 0.4rem;
    overflow: scroll;
  }
  .orderItem{
    display: flex;
    flex-direction: column;
  }
  .orderItem .time{
    margin-top: 0.2rem;
    margin-left: 0.2rem;
    color: #ee0606;
    font-size: 0.34rem;
  }
  .orderItem .detailItem{
    height: min-content;
    margin-top: 0.2rem;
    display: flex;
    flex-direction: row;
    font-size: 0.34rem;
    color: #131313;
    border-bottom: #9a9a9a solid 1px;
    padding-bottom: 0.2rem;
  }
  .orderItem .detailItem .name{
    margin-left: 0.86rem;
  }
  #footer{
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 9%;
    background: white;
    position: absolute;
    bottom: 0;
  }
  #footer span{
    margin-left: 0.2rem;
    margin-top: 0.28rem;
    font-size: 0.4rem;
  }
  #footer button{
    margin-left: 0.4rem;
    margin-right: 0;
    padding-left: 12px;
    width: 2rem;
    margin-top: 0.14rem;
    font-weight: bolder;
    line-height: 0.85rem;
    text-align: center;
    height: 0.85rem;
    background: white;
    border: #de9b21 solid 1px;
    color: #de9b21;
  }
  #footer .totalPrice{
    color: red;
  }
  #footer .order{
    margin-left: 0.2rem;
    width: 1.8rem;
  }
  .dialog{
    box-shadow: 0 0 10rem 10rem rgba(0,0,0,0.5);
    border-radius: 10px;
    background: white;
    width: 86%;
    height: 30%;
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    top: 4.3rem;
    left: 0.5rem;
  }
  .dialog span{
    margin-left: auto;
    margin-right: auto;
  }
  .dialog .success{
    margin-top: 0.3rem;
    margin-bottom: 0.5rem;
    font-weight: bold;
    font-size: 0.4rem;
  }
  .dialog button{
    width: 100%;
    background: #e73822;
    margin-top: auto;
    color: white;
    height: 0.98rem;
    line-height: 0.98rem;
    text-align: center;
    font-size: 0.3rem;
  }
</style>
